package xin.marcher.module.seller.mq.consumer;

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.exception.MQClientException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import xin.marcher.module.common.constants.RocketMqConstant;
import xin.marcher.module.seller.mq.config.RocketMQProperties;
import xin.marcher.module.seller.mq.consumer.listener.SellerPreheatCacheListener;


/**
 * 
 */
@Configuration
public class ConsumerBeanConfig {

    /**
     * 配置内容对象
     */
    @Autowired
    private RocketMQProperties rocketMQProperties;

    /**
     * 卖家缓存预热消费者
     *
     * @param preheatCacheListener
     * @return
     * @throws MQClientException
     */
    @Bean("sellerPreheatCacheTopic")
    public DefaultMQPushConsumer createItemStageConsumer(SellerPreheatCacheListener preheatCacheListener) throws MQClientException {
        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(RocketMqConstant.PREHEAT_SELLER_CACHE_BUCKET_GROUP);
        consumer.setNamesrvAddr(rocketMQProperties.getNameServer());
        consumer.subscribe(RocketMqConstant.PREHEAT_SELLER_CACHE_BUCKET_TOPIC, "*");
        consumer.registerMessageListener(preheatCacheListener);
        consumer.start();
        return consumer;
    }
}
